from rest_framework import serializers
from .models import DeliveryStaff, Delivery

class DeliveryStaffSerializer(serializers.ModelSerializer):
    username = serializers.CharField(source='user.username', read_only=True)
    phone = serializers.CharField(source='user.phone', read_only=True)

    class Meta:
        model = DeliveryStaff
        fields = ['id', 'user', 'username', 'phone', 'is_active', 'created_at']
        read_only_fields = ['created_at']

class DeliverySerializer(serializers.ModelSerializer):
    order_number = serializers.CharField(source='order.order_number', read_only=True)
    staff_name = serializers.CharField(source='staff.user.username', read_only=True)
    delivery_address = serializers.CharField(source='order.address', read_only=True)

    class Meta:
        model = Delivery
        fields = ['id', 'order', 'order_number', 'staff', 'staff_name', 
                 'status', 'delivery_address', 'created_at', 'completed_at']
        read_only_fields = ['created_at', 'completed_at'] 